import publicForm1 from "@/components/public/files-forms.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项
import CustomDialog from "@/components/rawMaterialManage/entryLedgerText/materialInfo/index.vue";
import publicForm from "@/components/public/el-form.vue"; //弹框form
import publicForm2 from "@/components/public/el-forms.vue"; //弹框form

import FormLyout from '@/components/commonPublic/fromLayout.vue'
import actions from "@/actions";
import uploads from "@/components/public/el-upload.vue";
import pdfDialog from "@/components/public/pdf-dialog";

import {
    nanoid
} from "nanoid";
import {
    getSpecificationDataList, //规格型号
    saveMaterialManage, //保存
    getJLMaterialManage, //详情
    getSpeciesDataList, //种类
    getPurveyorDataList, //厂商/供应商
    saveAudit, //审核
    getUserCompanyTreeList,
    getBaseDepartmentUser,
} from "@/api/request.js";
export default {
    data() {
        return {
            reverse: true,
            // 选择人
            dialogEditVisibleTree: false,
            loadingEditDialogTree: false,
            
            companyInfo: [], //公司树信息
            highlightBd: true,
            defaultProps: {
                children: "children",
                label: "fShortname",
            },
            departmentList: [], //部门
            num: null,
            personList: [], //人员列表新增
            checkboxGroup1: [],
            boys: require("@/assets/img/organization/boys.png"),
            girls: require("@/assets/img/organization/girls.png"),
            newData: null,
            treeText: {
                companyId: null,
                userId: null,
                text: null,
            },
            propText: null,
            candidate: null,
            // 选择人
            visible: "",
            varietyData: [], //材料种类数组
            materialData: [], //材料名称数组
            tableObj: [],
            tableData: [], //备案材料

            // 厂家证明资料
            // 文件上传
            dialogUpload: false,
            dialogVisibles: false,
            fileDetail: null,
            cndIndex: null, //弹框唯一标志
            pdfNum: null,

            // 厂家证明资料
            //施工单位检测报告
            sgIndex: null,
            sgdialogUpload: false,
            sgdialogVisibles: false,
            sgfileDetail: null,
            sgpdfNum: null,
            //施工单位检测报告
            loading: false,
            title: null,
            isLock: false,
            dialogHeight: null,
            formObj: formJs.formObj1,
            additionalObj: formJs.additionalObj,
            isEdit: false,
            currntData: null,
            dataInfo: null,
            startDates: null,
            treeData: [], //材料种类
            formData: {
                fId: "", //主键id
                filingCode: "", //备案编号
                merchantId: "", //生产厂商id
                approvalProve: "", //本次报批产能证明
                merchantReport: "", //厂家型式检验报告
                merchantOther: "", //厂家其他资料
                haveSupplier: "", //是否有供应商
                supplierId: "", //供应商id
                companyId: "", //标段id
                companyName: "", //标段名称
                declareDescribe: "", //申报描述
                declareUser: "", //申报人
                declareDates: "", //申报日期
                supplierEmpower: "", //供应商经销授权书
                supplierOther: "", //其他资料
                merchantName: "", //生产厂商名称
                supplierName: "", //供应商名称
                auditStatus: "", //审核状态
                merchantUSCC: "", //生产厂家统一社会信用代码
                merchantAdree: "", //生产厂家地址
                merchantLicense: "", //生产厂家营业执照
                merchantProduction: "", //厂家生产许可证
                supplierLicense: "", //供应商营业执照
                supplierUSCC: "", //供应商统一社会信用代码
                supplierAdree: "", //供应商地址
                materialapprovaldeatilList: [],
                recordfiles: [],
                engineeringParts: "",
                userId: "",
                reviewComments: "", //审核意见
                auditUnit: "", //审核单位
                findingsAudit: "", //审核结果
                auditDates: "", //审核日期
                haveNext: "", //是否有下一级审批
                nextUserId: "", //下一级审核人id
                nextUserName: "", //下一级审核人名称
                auditUserId: "", //当前提交人id
                auditUserName: "" //当前移交人名称


            },
            formDatafileList: [], //工作计划资料
            btnShow: false,
            currentDetail: null,
            selectPostionObj: [],
            types: [],
            // 材料弹框
            materialRow: {},
            materialShow: false,


            primaryInfo: null,


            // 文件
            filesNum: [4, 5, 6, 7, 8, 13, 14, 15],
            approvalProveList: [], //本次报批产能证明
            merchantReportList: [], //厂家型式检验报告
            merchantOtherList: [], //厂家其他资料
            supplierEmpowerList: [], //供应商经销授权书
            supplierOtherList: [], //其他资料


            merchantLicenseList: [], //生产厂家营业执照
            merchantProductionList: [], //厂家生产许可证
            supplierLicenseList: [], //供应商营业执照
            // 文件
            submitStatus: "有",
            handleObj: formJs.handleObj,
            handleObj1: formJs.handleObj1,

            // 页签切换
            typeData: [{
                    text: "基础信息",
                    show: true
                },
                {
                    text: "历史审核信息",
                    show: false
                },
            ],
            auditData: [],
            text: null,
            formDataCopy: null,
        };
    },
    components: {
        publicForm,
        publicForm1,
        publicForm2,
        FormLyout,
        CustomDialog,
        uploads,
        pdfDialog
    },


    mounted() {
        this.primaryInfo = JSON.parse(sessionStorage.getItem("GxEmbedded_primaryInfo"))
        actions.onGlobalStateChange((state, prev) => {
            var data = prev.currentUser.projects;
            this.userInfo = prev.currentUser;
        }, true);
        console.log('this.primaryInfo', this.primaryInfo);
        if (this.primaryInfo.status == 1) { //新增
            this.btnShow = true
            this.getSpeciesList(0, '') //获取种类材料
            this.formData.companyId = this.primaryInfo.fCompanyid;
            this.formObj.map((item) => {
                item.disabled = false;
            });
            this.yj_searchForm("1");
            this.yj_searchForm("2");
            this.getDetail({
                fId: "",
                fCompanyid: this.primaryInfo.fCompanyid,
                projectId: this.primaryInfo.fProjectid,
            })
            this.formObj[0].disabled = true;
            // this.formObj[2].disabled = true;
            // this.formObj[3].disabled = true;
            // this.formObj[11].disabled = true;
            // this.formObj[12].disabled = true;

            this.isEdit = false;
            this.additionalObj.map((item) => {
                item.disabled = false;
            });
            this.additionalObj[0].disabled = true;
            this.additionalObj[0].uploadSelect = true

            this.filesNum.map(item => {
                this.formObj[item].uploadSelect = true;
            })
        } else if (this.primaryInfo.status == 2) { //编辑
            this.formData.fId = this.primaryInfo.data.fId //按钮 
            this.getTender(this.primaryInfo.fProjectid);
            this.getDetail({
                fId: this.primaryInfo.data.fId
            })
            // this.formObj.map((item) => {
            //     item.disabled = true;
            // });
            this.formObj[0].disabled = true;
            // this.formObj[2].disabled = true;
            // this.formObj[3].disabled = true;
            this.isEdit = false;
            this.additionalObj.map((item) => {
                item.disabled = false;
            });
            this.additionalObj[0].uploadSelect = true;
            this.additionalObj[0].disabled = true;
            this.btnShow = true
        } else if (this.primaryInfo.status == 7) { //查看
            this.btnShow = false
            this.getDetail({
                fId: this.primaryInfo.data.fId
            })
            this.formObj.map((item) => {
                item.disabled = true;
            });
            this.isEdit = true

            this.additionalObj.map((item) => {
                item.disabled = true;
            });
            this.additionalObj[0].uploadSelect = false;

            this.handleObj.map((item) => {
                item.disabled = true;
            });
            this.handleObj[2].inputButton = false;
        } else if (this.primaryInfo.status == 6) { //审核
            this.btnShow = false
            this.getDetail({
                fId: this.primaryInfo.data.fId
            })
            this.formObj.map((item) => {
                item.disabled = true;
            });

            this.isEdit = true

            this.additionalObj.map((item) => {
                item.disabled = true;
            });
            this.additionalObj[0].uploadSelect = false;
            this.handleObj.map((item) => {
                item.disabled = false;
            });
            this.handleObj[2].disabled = true;
            this.handleObj[3].disabled = true;
            this.handleObj[2].inputButton = true;


        }

    },
    methods: {
        // 页签切换
        changeType(e, index) {
          
            for (let i in this.typeData) {
                if (parseFloat(i) === index) {
                  
                    this.typeData[i].show = true;
                } else {
                    this.typeData[i].show = false;
                }
            }
            // this.typeDataNum = index;
        },
        // 树选人
        // 树结构
        clickDialog(index, prop) {
            this.dialogEditVisibleTree = true;
        },
        getBaseCompanyList(id) {
            this.treeText = {
                companyId: id,
                userId: this.userInfo.id,

            };

            this.personList = [];
            this.departmentList = [];
            // this.dialogEditVisibleTree = true;
            this.loadingEditDialogTree = true;
            getUserCompanyTreeList(this.treeText)
                .then((res) => {
                    this.loadingEditDialogTree = false;
                    if (res.errcode == 0) {
                 
                        this.getBaseDepartmentUser(res.data.userCompanyTreeList[0].fCompanyid)

                        // this.companyTreeData = res.data.userCompanyTreeList;
                        // this.companyInfo = this.tranListToTreeData(
                        //     res.data.userCompanyTreeList
                        // );
                    } else {
                        this.$message.error("获取组织机构单位", res.msg);
                    }
                })
                .catch((error) => {
                    console.log("获取组织机构单位,接口报错", error);
                });
        },

        getBaseDepartmentUser(id) {
            getBaseDepartmentUser({
                    fCompanyid: id
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        // this.departmentList = res.data.childList;

                        this.personList = res.data.childList[0].personList;
                    } else {
                        this.$message.error("部门管理-查询部门列表以及下属人员", res.msg);
                    }
                })
                .catch((error) => {
                    console.log("部门管理-查询部门列表以及下属人员,接口报错", error);
                });
        },

        selectRealname(e, data) {
            data.map((item) => {
                if (e == item.fUserid) {
                    this.newData = item;
                }
            });
        },
        // 保存
        submitMember() {

            this.formData.nextUserId = this.newData.fAccount;
            this.formData.nextUserName = this.newData.fRealname;
            this.dialogEditVisibleTree = false;
        },
        // 树选人
        // 供应商/厂家
        yj_searchForm(num) {

            var obj = {
                page: 1,
                pageSize: 500,
                merchantName: "", //生产厂家
                typ: num //"1"材料生产商，"2"材料供应商
            }

            getPurveyorDataList(obj)
                .then((res) => {
                    if (res.errcode == 0) {

                        console.log(9, num, this.formObj);
                        if (num == 1) {
                            this.formObj[1].options = []
                            res.data.pageInfo.list.map(item => {
                                this.formObj[1].options.push({
                                    label: item.fMerchantname,
                                    value: item.fId,
                                    data: item
                                })
                            })
                        } else if (num == 2) {
                            this.formObj[10].options = []
                            res.data.pageInfo.list.map(item => {
                                this.formObj[10].options.push({
                                    label: item.fMerchantname,
                                    value: item.fId,
                                    data: item
                                })
                            })

                        }




                    } else {
                        this.$message.error({
                            content: '列表数据获取失败' + res.msg,
                            duration: 1000
                        })
                        this.loading = false;
                    }
                })

        },
        // 厂家证明资料
        // 关闭弹框
        closeDialog() {
            this.dialogUpload = false;
            this.$forceUpdate();
        },
        //   上传
        clickUpload(num) {
            this.cndIndex = num;
            this.dialogUpload = true;
        },
        getFile(val, index) {
            this.tableObj[index].merchantDatas = val;

            this.tableData = this.tableObj;
            this.$forceUpdate();
            // return val;
        },
        openPdfs(v, num) {
            // this.pdfNum=num;
            this.dialogVisibles = true;
            this.fileDetail = v;
        },
        //   厂家证明资料
        //施工单位检测报告
        sgcloseDialog() {
            this.sgdialogUpload = false;
        },
        //   上传
        sgclickUpload(num) {
            this.sgIndex = num;
            this.sgdialogUpload = true;
        },
        sggetFile(val, index) {
            this.tableObj[index].constructionReports = val;
            this.tableData = this.tableObj;
            this.$forceUpdate();
        },
        sgopenPdfs(v) {
            this.sgdialogVisibles = true;
            this.sgfileDetail = v;
        },
        //施工单位检测报告
        delteFile1(file, indexs, num) {
            var fileList;

            if (num == 0) { //厂家证明资料
                fileList = JSON.stringify(this.tableObj[indexs].merchantDatas);
            } else if (num == 1) { //施工单位检测报告
                fileList = JSON.stringify(this.tableObj[indexs].constructionReports);
            }
            for (let index = 0; index < JSON.parse(fileList).length; index++) {
                if (file.uid == JSON.parse(fileList)[index].uid) {
                    if (JSON.parse(fileList)[index].atta == undefined) {
                        this.tableObj[indexs].recordfiles.push({
                            fId: JSON.parse(fileList)[index].fId,
                        });
                    } else {
                        this.tableObj[indexs].recordfiles.push({
                            fId: JSON.parse(fileList)[index].atta.fId,
                        });
                    }

                    JSON.parse(fileList).splice(index, 1);
                }
            }
            this.tableData = this.tableObj;

        },
        // 材料种类
        getSpeciesList(num, data) {
            var obj = {
                page: 1,
                pageSize: 500
            }
            getSpeciesDataList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        res.data.pageInfo.list.map(item => {
                            if (item.fFilingmaterial == "是") {
                                this.varietyData.push(item)
                            }
                            if (num == 1) {
                                this.tableObj = [];
                                var materialData = []
                                data.map((item, index) => {
                                    this.varietyData.map(i => {

                                        if (i.fVarietyid == item.varietyId) {
                                            materialData = i.materialList;

                                        }
                                    })


                                    this.tableObj.push({
                                        varietyData: this.varietyData, //材料种类
                                        specifications: [], //规格型号
                                        materialData: materialData, //材料种类
                                        fId: item.fId,
                                        companyId: item.companyId,
                                        materialApprovalId: item.materialApprovalId,
                                        varietyId: item.varietyId, //材料种类id
                                        varietyName: item.varietyName, //材料种类名称
                                        materialId: item.materialId, //材料id
                                        materialName: item.materialName, //材料名称
                                        specificationId: item.specificationId, //材料规格id
                                        specificationName: item.specificationName, //材料规格名称
                                        filingLevel: item.filingLevel, //备案层级
                                        merchantData: item.merchantData, //厂家证明资料
                                        constructionReport: item.constructionReport, //施工单位检测报告
                                        engineeringPart: item.engineeringPart == '' ? [] : item.engineeringPart.split(","), //工程部位
                                        recordfiles: [],
                                        merchantDatas: item.merchantDatas,
                                        constructionReports: item.constructionReports
                                    })


                                    this.gets(item.materialId, index)
                                })

                                this.tableData = this.tableObj;
                                this.$forceUpdate();
                            }
                        })

                    } else {

                        this.$message.error({
                            content: res.msg,
                            duration: 1000
                        })
                        return false;
                    }
                })
                .catch(() => {
                    return false;
                });
        },
        // 选择材料种类
        varietySelect(data, index, row) {

            this.tableObj[index].varietyName = data.fVarietyname;
            this.tableObj[index].varietyId = data.fVarietyid;
            this.tableObj[index].materialData = data.materialList;
            this.tableObj[index].filingLevel = data.fFilinglevel
            // this.tableObj[index]['currentRow'] = data.materialList;
            this.tableData = this.tableObj;
            this.$forceUpdate()
        },
        //材料名称选择
        selectMaterial(data, index, row, name) { //存放位置选择
            this.tableObj[index].materialName = data.fMaterialname;
            this.tableObj[index].materialId = data.fMaterialid;
            this.gets(data.fMaterialid, index)
            this.$forceUpdate()

        },
        gets(id, index) {
            var obj = {
                page: 1,
                pageSize: 500,
                name: "", //材料种类/名称
                fVersion: "", //规格型号
                fId: id
            }
            this.tableObj[index].specifications = []
            var that = this;
            getSpecificationDataList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        if (res.data.pageInfo.list.length > 0) {
                            var data = res.data.pageInfo.list;
                            this.tableObj[index].specifications = data;
                        }

                        this.$forceUpdate()
                        this.tableData = this.tableObj;
                        // that.$forceUpdate()
                        // that.tableData = this.tableObj


                    } else {

                        this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })



        },
        // 规格型号
        selectSpecification(data, index, row) {
            this.tableObj[index].specificationName = data.fVersion;
            this.tableObj[index].specificationId = data.fVersionid;
            this.tableData = this.tableObj;
        },
        // 存放位置
        addUnqualifiedInfo() {
            this.tableObj.push({
                varietyData: this.varietyData, //材料种类
                specifications: [], //规格型号
                materialData: [], //材料种类
                fId: this.userInfo.id + nanoid(),
                companyId: "",
                materialApprovalId: "",
                varietyId: "", //材料种类id
                varietyName: "", //材料种类名称
                materialId: "", //材料id
                materialName: "", //材料名称
                specificationId: "", //材料规格id
                specificationName: "", //材料规格名称
                filingLevel: "", //备案层级
                merchantData: 'me' + this.userInfo.id + nanoid(), //厂家证明资料
                constructionReport: 'co' + this.userInfo.id + nanoid(), //施工单位检测报告
                engineeringPart: "", //工程部位
                recordfiles: [],
                constructionReports: [],
                merchantDatas: []
            });
            this.tableData = this.tableObj;


        },
        // 删除存放位置
        deleteUnqualifiedInfo(index, row) {
            this.tableData.splice(index, 1);
            this.tableObj.splice(index, 1);
        },
        async getTender(e) {
            await this.$http(
                "http://172.18.5.31:8300/IOTManagement/Base/Company/getGXJLBaseCompanyList.do?projectId=" +
                e, {
                    headers: {
                        "Content-Type": "application/json",
                        Authorization: localStorage.getItem("access_token"),
                    },
                }
            ).then((res) => {
                if (res.status == 200) {
                    var data = res.data.data.GXCompanyList;


                }
            });
        },
        selectChange(data, index, prop) {
            console.log(data.data, index, prop);
            if (prop == "haveSupplier") {
                if (data == '无') {

                    this.yj_searchForm("1");
                    this.formObj = formJs.formObj;
                    this.submitStatus = data;
                    this.formData.haveSupplier = data;
                    // this.$forceUpdate();


                } else if (data == '有') {
                    this.formObj = formJs.formObj1;
                    // this.formObj[11].disabled = true;
                    // this.formObj[12].disabled = true;
                    this.formData.haveSupplier = "有";
                    this.yj_searchForm("1");
                    this.yj_searchForm("2");
                    this.submitStatus = data;
                }


            } else
            if (prop == 'merchantName') { //生产厂家名称
                // this.formData.fSamplename = value.label || value
                this.formData.merchantUSCC = data.data == undefined ? "" : data.data.fUscc; //生产厂家统一社会信用代码
                this.formData.merchantAdree = data.data == undefined ? "" : data.data.fMerchantadree; //生产厂家地址
                this.formData.merchantId = data.data == undefined ? "" : data.data.fId;
                this.formData.merchantName = data.data == undefined ? data : data.data.fMerchantname;
                this.merchantLicenseList = data.data == undefined ? [] : data.data.fBusinessLicenses; //生产厂家营业执照
                this.merchantProductionList = data.data == undefined ? [] : data.data.fProductionLicenses; //厂家生产许可证
                this.formData.merchantProduction = data.data == undefined ? this.formDataCopy.merchantProduction : data.data.fProductionLicense;
                this.formData.merchantLicense = data.data == undefined ? this.formDataCopy.merchantLicense : data.data.fBusinessLicense;
            } else if (prop == 'supplierName') { //供应商
                this.formData.supplierId = data.data == undefined ? "" : data.data.fId;
                this.formData.supplierName = data.data == undefined ? data : data.data.fMerchantname;
                this.formData.supplierUSCC = data.data == undefined ? "" : data.data.fUscc; //生产厂家统一社会信用代码
                this.formData.supplierAdree = data.data == undefined ? "" : data.data.fMerchantadree; //生产厂家地址
                this.supplierLicenseList = data.data == undefined ? [] : data.data.fBusinessLicenses; //供应商营业执照
                this.formData.supplierLicense = data.data == undefined ? this.formDataCopy.supplierLicense : data.data.fBusinessLicense;
            } else if (prop == 'haveNext') {
                if (data == '是') {
                    this.handleObj[2].rules[0].required = true;
                } else {
                    this.handleObj[2].rules[0].required = false;
                }
            } else if (prop == 'findingsAudit') {
                if (this.formData.haveNext == '是') {


                    if (data == '不通过') {
                        this.formData.haveNext = "否";
                        this.handleObj[1].inputButton = false;
                        this.handleObj[1].rules[0].required = false;
                    } else if (data == '通过') {
                        this.formData.haveNext = this.text;
                        this.handleObj[1].inputButton = true;
                        this.handleObj[1].rules[0].required = true;
                    }
                } else if (this.formData.haveNext == '否') {
                    if (data == '不通过') {
                        this.formData.haveNext = "否";
                        this.handleObj[1].inputButton = false;
                        this.handleObj[1].rules[0].required = false;
                    } else if (data == '通过') {
                        this.formData.haveNext = this.text;
                        this.handleObj[1].inputButton = false;
                        this.handleObj[1].rules[0].required = false;
                    }
                }
            }
        },

        edit() {
            this.formData = this.$options.data.call(this).formData;
        },

        // 刪除文件
        delteFile(file, num) {
            var that = this;

            var fileList;
            if (num == 0) {
                fileList = JSON.stringify(this.supplierEmpowerList); //供应商经销授权书

            } else if (num == 1) {
                fileList = JSON.stringify(this.merchantReportList); //厂家型式检验报告
            } else if (num == 2) {
                fileList = JSON.stringify(this.merchantOtherList); //厂家其他资料
            } else if (num == 3) {
                fileList = JSON.stringify(this.approvalProveList); //本次报批产能证明
            } else if (num == 4) {
                fileList = JSON.stringify(this.supplierOtherList); //其他资料
            }
            for (let index = 0; index < JSON.parse(fileList).length; index++) {
                if (file.uid == JSON.parse(fileList)[index].uid) {
                    if (JSON.parse(fileList)[index].atta == undefined) {
                        this.formData.recordfiles.push({
                            fId: JSON.parse(fileList)[index].fId,
                        });
                    } else {
                        this.formData.recordfiles.push({
                            fId: JSON.parse(fileList)[index].atta.fId,
                        });
                    }
                    JSON.parse(fileList).splice(index, 1);
                }
            }

        },
        // 详情
        getDetail(obj) {
            this.loading = true;
            getJLMaterialManage(obj).then((res) => {
                if (res.errcode == 0) {
                    this.loading = false;
                    var data = res.data.yjQmpClJlmaterialapproval;
                    this.formDataCopy = data;
                    var infoNum = [0]

                    if (obj.fId == "") {
                        this.formData.filingCode = data.filingCode;
                        this.formData.approvalProve = data.approvalProve;
                        this.formData.merchantOther = data.merchantOther;
                        this.formData.merchantReport = data.merchantReport;
                        this.formData.supplierOther = data.supplierOther;
                        this.formData.supplierEmpower = data.supplierEmpower;
                        this.formData.declareUser = this.userInfo.userName;
                        this.formData.supplierLicense = data.supplierLicense;//供应商
                        this.formData.merchantProduction = data.merchantProduction;//生产厂家生产许可证
                        this.formData.merchantLicense = data.merchantLicense;//企业营业执照
                        this.formData.declareDates = this.common.day(0); //当前登录人id
                        this.formData.haveSupplier = "有";
                        this.formData.auditStatus = "";
                        this.formData.fId = data.fId;
                    } else {
                        // if(data.auditStatus=='已提交'){

                        // }
                        this.auditData = res.data.audit;
                        if (data.haveSupplier == "有") {
                        
                            this.formObj = formJs.formObj1;
                            this.yj_searchForm("1");
                            this.yj_searchForm("2");

                            if (this.primaryInfo.status == 7 || this.primaryInfo.status == 6) {
                                this.filesNum.map(item => {
                                    this.formObj[item].uploadSelect = false;
                                })


                                this.formObj.map((item) => {
                                    item.disabled = true;
                                });
                                this.isEdit = true

                                this.additionalObj.map((item) => {
                                    item.disabled = true;
                                });
                                this.additionalObj[0].uploadSelect = false;


                            } else {
                                this.filesNum.map(item => {
                                    this.formObj[item].uploadSelect = true;
                                })
                                // this.formObj.map((item) => {
                                //     item.disabled = true;
                                // });


                                this.isEdit = false;
                                this.additionalObj.map((item) => {
                                    item.disabled = false;
                                });
                                this.additionalObj[0].uploadSelect = true;
                                this.additionalObj[0].disabled = true;

                            }
                        } else if (data.haveSupplier == "无") {
                          
                     
                            this.formObj = formJs.formObj;
                            this.yj_searchForm("1");
                            if (this.primaryInfo.status == 7 || this.primaryInfo.status == 6) {
                                this.filesNum.map(item => {
                                    if (item < 10) {
                                        this.formObj[item].uploadSelect = false;
                                    }

                                })
                                this.formObj.map((item) => {
                                    item.disabled = true;
                                });
                                this.isEdit = true

                                this.additionalObj.map((item) => {
                                    item.disabled = true;
                                });
                                this.additionalObj[0].uploadSelect = false;
                            } else {
                                this.filesNum.map(item => {
                                    if (item < 10) {
                                        this.formObj[item].uploadSelect = true;
                                    }
                                })
                                this.formObj.map((item) => {
                                    item.disabled = false;
                                });

                                this.isEdit = false;
                                this.additionalObj.map((item) => {
                                    item.disabled = false;
                                });
                                this.additionalObj[0].uploadSelect = true;
                                this.additionalObj[0].disabled = true;
                            }
                        }

                        this.submitStatus = data.haveSupplier;
                        this.formData = data;
                        this.getSpeciesList(1, data.materialapprovaldeatilList) //获取种类材料
                        this.approvalProveList = res.data.approvalProves; //本次报批产能证明
                        this.merchantReportList = res.data.merchantReports; //厂家型式检验报告
                        this.merchantOtherList = res.data.merchantOthers; //厂家其他资料
                        this.supplierEmpowerList = res.data.supplierEmpowers; //供应商经销授权书
                        this.supplierOtherList = res.data.supplierOthers; //其他资料
                        this.merchantLicensesList = res.data.merchantLicenses //厂家营业执照
                        this.merchantLicenseList = res.data.merchantLicenses; //生产厂家营业执照
                        this.merchantProductionList = res.data.merchantProductions; //厂家生产许可证
                        this.supplierLicenseList = res.data.supplierLicenses; //供应商营业执照

                    }


                    if (this.primaryInfo.status == 7) {
                        this.btnShow = false;
                    } else if (this.primaryInfo.status == 6) {
                        this.text = this.formData.haveNext;
                        if (this.formData.haveNext == '是') {
                            this.handleObj[1].rules[0].required = true;
                            this.handleObj[1].inputButton = true;
                        } else {
                            this.handleObj[1].rules[0].required = false;
                            this.handleObj[1].inputButton = false;

                        }

                        this.formData.auditUserName = this.userInfo.userName;
                        this.formData.auditUserId = this.userInfo.id;
                        this.formData.auditDates = this.common.day(0); //当前登录人id
                        this.btnShow = true;

                        this.getBaseCompanyList(data.auditCompanyId)

                    } else {
                        this.btnShow = true;
                    }
                } else {
                    this.loading = false;
                    this.$message.error({
                        content: res.msg,
                        duration: 1000
                    })
                }
            });
        },

        yj_saveForm() {

            // this.formData.fReportid = this.userInfo.id; //当前登录人id
            // this.formData.fReportname = this.userInfo.userName; //当前登录人名称

            // this.formData.userName = this.userInfo.userName; //当前登录人名称
            // this.formData.fProjectid = this.userInfo.projectId; //项目名称id
            // this.formData.fProjectname = this.userInfo.projectName; //项目名称


            var str = "";
            if (this.tableData.length > 0) {
                this.tableData.map(item => {
                    console.log(item.engineeringPart, item.engineeringPart.length);
                    if (item.engineeringPart.length > 0) {
                        item.engineeringPart = item.engineeringPart.join(",")
                        str += item.engineeringPart + ","
                    } else {
                        item.engineeringPart = ''
                    }


                })
                this.formData.engineeringPart = str;
            }

            this.formData.materialapprovaldeatilList = this.tableData;


            // 存放位置

            // 0连续新增1新增
            if (this.formData.auditStatus == '' || this.formData.auditStatus == '待提交' || this.formData.auditStatus == '待退回') {


                if (this.$refs.publicForm.submitForm()) {
                    // saveAudit
                    this.saveForm(this.formData);
                } else {
                    console.log("error");
                }
            } else {
                var data = {
                    fId: this.formData.fId, //当前报验数据的主表id
                    haveNext: this.formData.haveNext, //是否有下一级审核
                    nextUserId: this.formData.nextUserId, //下一级审核人ID
                    nextUserName: this.formData.nextUserName, //下一级审核人名称
                    auditUserId: this.formData.auditUserId, //审核人loginName
                    auditUserName: this.formData.auditUserName, //审核人
                    auditDates: this.formData.auditDates, //审核日期
                    findingsAudit: this.formData.findingsAudit, //审核结果
                    reviewComments: this.formData.reviewComments, //审核建议
                    auditUnit: this.userInfo.companyName //当前登录人机构性质
                }
                if (this.$refs.publicForm2.submitForm()) {
                    // saveAudit
                    this.saveForm(data);
                } else {
                    console.log("error");
                }
            }

        },
        // 保存haveNext
        saveForm(data) {
            this.loading = true;
            this.isLock = true;
            var str;
            this.formData.userId = this.userInfo.loginName; //当前登录人id
            if (data.auditStatus == '' || data.auditStatus == '待提交' || data.auditStatus == '待退回') {
                str = saveMaterialManage;

            } else {
                str = saveAudit;
            }

            str(data)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.loading = false;
                        this.visible = false;
                        this.$router.push({
                            path: "/rawMaterialManage/filingMaterialsManage/materialManufacturerApproval",

                        });
                        window.sessionStorage.removeItem("GxEmbedded_primaryInfo");
                        this.$message.success({
                            content: "新增成功",
                            duration: 1000
                        })
                        // this.$emit("refreshList");
                        // this.$message.success("新增成功");
                        this.isLock = false
                    } else {
                        this.loading = false;
                        this.isLock = false

                        this.$message.error({
                            content: res.msg,
                            duration: 1000
                        })
                        console.log("接口报错");
                    }
                })
                .catch((error) => {
                    console.log("拌合站设置-新增）", error);
                });

        },
        refreshList() {},
        materialDialog() {
            this.materialShow = false;
        },
    },
};